package customview.ike.com.customviewproject;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

import customview.ike.com.customviewproject.widget.Refresh1.PullToRefreshLayout;
import customview.ike.com.customviewproject.widget.Refresh1.rotationArrow.RotationArrowFooterLayout;
import customview.ike.com.customviewproject.widget.Refresh1.rotationArrow.RotationArrowHeaderLayout;

public class MainActivity extends AppCompatActivity {
    // private ListView lv;
    private PullToRefreshLayout refresh_layout;
    private List<String> data = new ArrayList<>();
    private Handler handler = new Handler();
    private String Tag = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       // lv= (ListView) findViewById(R.id.lv);
        refresh_layout= (PullToRefreshLayout) findViewById(R.id.refresh_layout);
        refresh_layout.setRefreshHeader(new RotationArrowHeaderLayout(this));
        refresh_layout.setRefreshFooter(new RotationArrowFooterLayout(this));
        for (int i=0;i<50;i++) {
            data.add("我是数据:"+i);
        }
       // lv.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,data));
        refresh_layout.setOnRefreshListener(new PullToRefreshLayout.RefreshListener() {
            @Override
            public void onRefresh() {
                handler.postDelayed(runnable,5000);
                Log.e(Tag,"下拉刷新");
            }

            @Override
            public void onLoadMore() {
                Log.e(Tag,"加载跟多");
                handler.postDelayed(runnable,5000);

            }

            @Override
            public void cancelRefresh() {
                Log.e(Tag,"取消下拉刷新");
                handler.removeCallbacks(runnable);

            }

            @Override
            public void cancelLoadMore() {
                Log.e(Tag,"取消加载跟多");
                handler.removeCallbacks(runnable);
            }
        });
    }
    private Runnable runnable = new Runnable() {
        @Override
        public void run() {
            refresh_layout.onRefreshComplete();
        }
    };
    
}